﻿using QingZhouLinYe.HttpApi.Models;
using QingZhouLinYe.HttpApi.Models.Converters;
using SqlSugar;
using System.Diagnostics;

namespace QingZhouLinYe.HttpApi
{
    public static class BaseClass
    {
        public static int CreateSysDataBase(SqlSugarClient db)
        {
            int x = 0;
            using (db)
            {
                db.DbMaintenance.CreateDatabase();   //创建数据库
                List<String> dbs = db.DbMaintenance.GetDataBaseList();  //获取所有数据库名称
                if (dbs.Exists(s => s != "QingZhouLinYe_Core"))   //判断数据库是否存在
                {

                }
                //创建表
                db.CodeFirst.InitTables(
                    typeof(FangHuoDanWei)
                 );



                //初始化基础数据
                {
                    List<FangHuoDanWei> fhdws = new List<FangHuoDanWei>();
                    FangHuoDanWei fhdw0 = new FangHuoDanWei();
                    fhdw0.MingCheng = "青州市";
                    fhdw0.Code = "370781";
                    fhdw0.UpCode = "3707";
                    fhdw0.CenterShape = new Point(118.334, 36.594, 4490);
                    fhdw0.MapLevel = 12;
                    //db.Insertable(fhdw0).ExecuteCommand();
                    fhdws.Add(fhdw0);
                    FangHuoDanWei fhdw1 = new FangHuoDanWei();
                    fhdw1.MingCheng = "防灭火巡查专业队";
                    fhdw1.Code = "37078100";
                    fhdw1.UpCode = "370781";
                    fhdw1.CenterShape = new Point(118.334, 36.594, 4490);
                    fhdw1.MapLevel = 12;
                    //db.Insertable(fhdw1).ExecuteCommand();
                    fhdws.Add(fhdw1);
                    FangHuoDanWei fhdw2 = new FangHuoDanWei();
                    fhdw2.MingCheng = "王坟镇";
                    fhdw2.Code = "37078101";
                    fhdw2.UpCode = "370781";
                    fhdw2.CenterShape = new Point(118.434, 36.494, 4490);
                    fhdw2.MapLevel = 12;
                    //db.Insertable(fhdw2).ExecuteCommand();
                    fhdws.Add(fhdw2);
                    FangHuoDanWei fhdw3 = new FangHuoDanWei();
                    fhdw3.MingCheng = "庙子镇";
                    fhdw3.Code = "37078102";
                    fhdw3.UpCode = "370781";
                    fhdw3.CenterShape = new Point(118.534, 36.394, 4490);
                    fhdw3.MapLevel = 12;
                    //db.Insertable(fhdw3).ExecuteCommand();
                    fhdws.Add(fhdw3);
                    db.Fastest<FangHuoDanWei>().BulkCopyAsync(fhdws);

                    x = 1;
                    Debug.WriteLine("QingZhouLinYe_test数据库创建成功！");
                }
                return x;
            }
        }
    }
}
